package com.ssyc.gsk_teacher.fragment;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.ssyc.common.base.LazyBaseFragment;
import com.ssyc.common.utils.UiUtils;
import com.ssyc.common.utils.WxAppUtils;
import com.ssyc.gsk_teacher.R;
import com.ssyc.gsk_teacher.activity.TeacherAssignHomeworkActivity;
import com.ssyc.gsk_teacher.activity.TeacherAttendanceManagementActivity;
import com.ssyc.gsk_teacher.activity.TeacherBirthdayActivity;
import com.ssyc.gsk_teacher.activity.TeacherEvaluateRecordActivity;
import com.ssyc.gsk_teacher.activity.TeacherLivingListActivity;
import com.ssyc.gsk_teacher.activity.TeacherPracticeActivity;
import com.ssyc.gsk_teacher.activity.TeacherRatifyLeaveListActivity;
import com.ssyc.gsk_teacher.activity.TeacherRedpackageVeriActivity;
import com.ssyc.gsk_teacher.activity.TeacherScoreManagerActivity;
import com.ssyc.gsk_teacher.activity.TeacherShowActivity;
import com.ssyc.gsk_teacher.activity.TeacherStudentFileActivity;
import com.ssyc.gsk_teacher.activity.TeacherSyllabusActivity;
import com.ssyc.gsk_teacher.activity.TeacherTakeLineListActivity;
import com.ssyc.gsk_teacher.adapter.HomeGvAdapter;
import com.ssyc.gsk_teacher.bean.HomeInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * 主页Fragment
 * Created by Administrator on 2018/6/12 0012.
 */

public class TeacherHomeFragment extends LazyBaseFragment implements AdapterView.OnItemClickListener {


    //展示选项的GridView
    private GridView mGv;

    //首页的展示的条目的数据集合
    private List<HomeInfo> homeInfos;

    //适配器对象
    private HomeGvAdapter adapter;

    //首页的栏目的所有图片


    //首页的栏目的所有图片
//    private int[] itemResId = {R.drawable.teacher_kcjd, R.drawable.teacher_jsfc, R.drawable.teacher_xsda, R.drawable.teacher_srtx,
//            R.drawable.teacher_pxb, R.drawable.teacher_qjsp, R.drawable.teacher_kqgl, R.drawable.teacher_bzzy, R.drawable.teacher_jpxgl2,
//            R.drawable.teacher_tk, R.drawable.teacher_cjgl, R.drawable.teacher_yzhb, R.drawable.teacher_jzpj, R.drawable.teacher_stzb, R.drawable.common_word};

    private int[] itemResId = {R.drawable.teacher_kcjd, R.drawable.teacher_jsfc, R.drawable.teacher_xsda, R.drawable.teacher_srtx,
            R.drawable.teacher_pxb, R.drawable.teacher_qjsp, R.drawable.teacher_kqgl, R.drawable.teacher_bzzy, R.drawable.teacher_jpxgl2,
            R.drawable.teacher_tk, R.drawable.teacher_cjgl, R.drawable.teacher_yzhb, R.drawable.teacher_jzpj, R.drawable.teacher_stzb};

    //首页的栏目名称
//    private String[] itemNames = {"课程进度", "教师风采", "学生档案", "生日提醒",
//            "排行榜", "请假审批", "考勤管理", "布置练习", "新概念2",
//            "题库", "成绩管理", "验证红包", "家长评价", "收听直播", "金牌单词王"};

    private String[] itemNames = {"课程进度", "教师风采", "学生档案", "生日提醒",
            "排行榜", "请假审批", "考勤管理", "布置练习", "新概念2",
            "题库", "成绩管理", "验证红包", "家长评价", "收听直播"};


    public static final String TAG = TeacherHomeFragment.class.getName();

    //单体模式
    private static class LazyHolder {
        private static final TeacherHomeFragment INSTANCE = new TeacherHomeFragment();
    }

    public static final TeacherHomeFragment newInstance() {
        return LazyHolder.INSTANCE;
    }

    @Override
    public void lazyInit(View view, Bundle savedInstanceState) {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.teacher_fragment_home;
    }

    @Override
    protected boolean isNeedShowTitle() {
        return false;
    }

    @Override
    protected String setTitleText() {
        return null;
    }

    @Override
    protected void init(View view, Bundle savedInstanceState) {
        super.init(view, savedInstanceState);
        showContent();

        //初始化视图
        initView(view);

        //初始化数据
        initData();

        //初始化列表
        initGv();

    }


    /**
     * 初始化视图
     */
    private void initView(View view) {
        mGv = view.findViewById(R.id.gv);
    }

    /**
     * 初始化数据
     */
    private void initData() {
        homeInfos = new ArrayList<>();
        for (int i = 0; i < itemNames.length; i++) {
            HomeInfo info = new HomeInfo();
            info.resId = itemResId[i];
            info.name = itemNames[i];
            homeInfos.add(info);
        }
    }

    /**
     * 初始化列表的方法
     */
    private void initGv() {
        adapter = new HomeGvAdapter(getContext(), homeInfos, R.layout.teacher_gv_home);
        mGv.setAdapter(adapter);
        mGv.setOnItemClickListener(this);
    }

    /**
     * 列表的条目点击事件
     *
     * @param adapterView
     * @param view
     * @param pos
     * @param l
     */
    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
        int index = pos + 1;
        if (index == 0) {
            //教学与反思
//            UiUtils.startActivity(getActivity(), TeacherFansiActivity.class);

            //开发中提示框
//            AlertDialogUtil.showAlertDialog(getActivity(), "程序GG正在努力开发中", new AlertDialogUtil.onClickListener() {
//                @Override
//                public void onClickOk() {
//                    CustomDialogManager.dissmiss();
//                }
//            });
        } else if (index == 1) {
            //课程进度
            UiUtils.startActivity(getActivity(), TeacherSyllabusActivity.class);
        } else if (index == 2) {
            //教师风采
            UiUtils.startActivity(getActivity(), TeacherShowActivity.class);
        } else if (index == 3) {
            //学生档案
            UiUtils.startActivity(getActivity(), TeacherStudentFileActivity.class);
        } else if (index == 4) {
            //生日提醒
            UiUtils.startActivity(getActivity(), TeacherBirthdayActivity.class);
        } else if (index == 5) {
            //排行榜
            UiUtils.startActivity(getActivity(), TeacherTakeLineListActivity.class);
        } else if (index == 6) {
            //请假审批
            UiUtils.startActivity(getActivity(), TeacherRatifyLeaveListActivity.class);
        } else if (index == 7) {
            //考勤管理
            UiUtils.startActivity(getActivity(), TeacherAttendanceManagementActivity.class);
        } else if (index == 8) {
            //布置练习
            UiUtils.startActivity(getActivity(), TeacherAssignHomeworkActivity.class);
        } else if (index == 9) {
            //金牌新概念2
            ARouter.getInstance().build("/student/NewConceptTwoActivity").navigation();
        } else if (index == 10) {
            //题库
            UiUtils.startActivity(getActivity(), TeacherPracticeActivity.class);
        } else if (index == 11) {
            //成绩管理
            UiUtils.startActivity(getActivity(), TeacherScoreManagerActivity.class);
        } else if (index == 12) {
            //验证红包
            UiUtils.startActivity(getActivity(), TeacherRedpackageVeriActivity.class);
        } else if (index == 13) {
            //家长评价
            UiUtils.startActivity(getActivity(), TeacherEvaluateRecordActivity.class);
        } else if (index == 14) {
            //收听直播
            UiUtils.startActivity(getActivity(), TeacherLivingListActivity.class);
        }
//        else if (index == 15) {
//            //测评
//            if ("0".equals(SPUtil.getString(getActivity(), SpKeys.ISSHOWCP))) {
//                //开发中提示框
//                AlertDialogUtil.showAlertDialog(getActivity(), "程序GG正在努力开发中", new AlertDialogUtil.onClickListener() {
//                    @Override
//                    public void onClickOk() {
//                        CustomDialogManager.dissmiss();
//                    }
//                });
//            } else {
//                ARouter.getInstance().build("/teacherappraisal/TkTeacherAppraisalMainActivity").navigation();
//
//            }
//        }
        else if (index == 15) {
            //金牌单词王
            WxAppUtils.launchWeApp(getContext());
        }
    }
}
